package com.mtask.web.controller;

import com.mtask.common.dto.TaskJobDTO;
import com.mtask.common.dto.TaskJobResponseDTO;
import com.mtask.web.service.TaskCrudService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RequestMapping("/job")
@RestController
public class TaskCrudController {
  @Resource private TaskCrudService taskCrudService;

  @PostMapping
  public void save(@RequestBody @Valid TaskJobDTO taskJobDTO) {
    taskCrudService.save(taskJobDTO);
  }

  @DeleteMapping("/{id}")
  public void delete(@PathVariable Integer id) {
    taskCrudService.deleteById(id);
  }

  @PostMapping("/all")
  public Page<TaskJobResponseDTO> findAll(@RequestBody PageRequest pageable) {
    return taskCrudService.findAll(pageable);
  }
}
